<?php

use yii\helpers\Html;
use yii\grid\GridView;

use app\models\Carousel;

/* @var $this yii\web\View */
/* @var $searchModel app\models\CarouselSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '轮播图管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="carousel-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a('新增轮播图', ['create'], ['class' => 'btn btn-success']) ?>
    </p>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'showOnEmpty'=>false,
        'layout'=>"{items}{pager}\n{summary}",

        'tableOptions' =>['class' => 'table table-striped'],
        'columns' => [
            //['class' => 'yii\grid\SerialColumn'],
            //'carousel_id',
            [
                'attribute' => 'carousel_id',
                'label' => '编号',
                'headerOptions' => array('style'=>'width:80px;'),
            ],
            //'image',
            [
                'attribute' => 'image',
                'label' => '轮播图片',
                'format' => 'html',
                'value' => function($model, $key, $index, $column){
                    if(!empty($model->image))
                        $image = '<img src=' . $model->image .' width=360px height=180px>';
                    else
                        $image = '';

                    return $image;
                },
                'filter'=> false,
                'headerOptions' => array('style'=>'width:160px;'),
            ],

            'link',
            'title',
            //'text:ntext',
            //'order_num',
            //'status',
            [
                'attribute' => 'status',
                'label' => '状态',
                'value'=>function ($model, $key, $index, $column) {
                    return Carousel::getStatusOption($model->status);
                },
                'filter'=> Carousel::getStatusOption(),
                'headerOptions' => array('style'=>'width:90px;'),
            ],

            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>

</div>
